import { http } from "@/utils/http";

export type BalancePaymentOrder = {
  id: number;
  order_no: string;
  user_id: number;
  amount: number;
  balance_used: number;
  status: number;
  transaction_no?: string;
  paid_at?: string;
  created_at: string;
  updated_at: string;
};

export type BalancePaymentOrderResponse = {
  success: boolean;
  code: number;
  message: string;
  data: BalancePaymentOrder;
};

export type BalancePaymentOrderListResponse = {
  success: boolean;
  code: number;
  message: string;
  data: BalancePaymentOrder[];
  pagination: {
    page: number;
    page_size: number;
    total: number;
    total_page: number;
  };
};

export type PaginationParams = {
  page?: number;
  page_size?: number;
};

/** 创建余额支付订单 */
export const createBalancePaymentOrder = (data: Partial<BalancePaymentOrder>) => {
  return http.request<BalancePaymentOrderResponse>("post", "/balance/order", { data });
};

/** 获取余额支付订单列表 */
export const getBalancePaymentOrders = (params?: PaginationParams) => {
  return http.request<BalancePaymentOrderListResponse>("get", "/balance/order", { params });
};

/** 获取余额支付订单详情 */
export const getBalancePaymentOrderById = (id: number) => {
  return http.request<BalancePaymentOrderResponse>("get", `/balance/order/${id}`);
};

/** 更新余额支付订单 */
export const updateBalancePaymentOrder = (id: number, data: Partial<BalancePaymentOrder>) => {
  return http.request<BalancePaymentOrderResponse>("put", `/balance/order/${id}`, { data });
};

/** 删除余额支付订单 */
export const deleteBalancePaymentOrder = (id: number) => {
  return http.request("delete", `/balance/order/${id}`);
};